package com.heima.minio;
 
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
 
import java.io.FileInputStream;
 
public class MinIOTest {
 
 
    public static void main(String[] args) {

        try {
            FileInputStream fileInputStream =  new FileInputStream("D:\\list.html");;
 
            //1.创建minio链接客户端  
            MinioClient minioClient = MinioClient.builder()
                            .credentials("minio", "minio123").endpoint("http://192.168.200.130:9000")
                    .build();
            //2.上传 对象
            PutObjectArgs putObjectArgs = PutObjectArgs.builder()
                    .object("list.html")//文件名
                    .contentType("text/html")//文件类型
                    .bucket("leadnews")//桶名词  与minio创建的桶名称 一致
                    .stream(fileInputStream, fileInputStream.available(), -1) //文件流（流stream，大小，传到哪）
                           //fileInputStream.available()代表有值就一直传递；-1代表传完所有文件
                    .build();
            minioClient.putObject(putObjectArgs);
        //上传完成
 
        //访问
            System.out.println("http://192.168.200.130:9000/leadnews/list.html");
 
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
 
}